<template>
  <div class="user-msg">
    <!-- 导航栏 -->
    <van-nav-bar title="短信息" left-arrow @click-left="$router.go(-1)" />
    <!-- body -->
    <div class="body">
      <div class="msg-item" v-for="m in msgList" :key="m.lastDateTime" @click="$router.push(`/dialogue/${m.receiverUserId}`)">
        <div class="item-left">
          <div class="item-top">
            <div class="top-left">
              <p class="name">{{ m.receiverUserNickName }}</p>
              <p class="time">
                {{ m.lastDateTime.substring(0, 10) }}
                {{ m.lastDateTime.substring(11, 19) }}
              </p>
            </div>
            <div class="top-right">
              <p>全部会话</p>
            </div>
          </div>
          <div class="main">
            <p>{{ m.lastMessage }}</p>
          </div>
        </div>
        <div class="item-right">
          <img
            :src="`https://file.ituring.com.cn/SmallCover/${m.receiverUserAvatarImageKey}`"
            :alt="m.receiverUserAvatarImageKey"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { MsgAPI } from "@/apis";
export default {
  data() {
    return {
      page: 1,
      msgList: [],
    };
  },
  mounted() {
    this.getMsg();
  },
  methods: {
    // 网络请求
    async getMsg() {
      // 主要网络请求
      let { data } = await this.$http(MsgAPI(this.page), {
        headers: {
          Authorization:
            "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiLoi6bnk5xfNzAwNiIsImp0aSI6IjYwODAyNiIsIlVzZXJJZCI6IjYwODAyNiIsImlhdCI6IjIwMjMvMi82IDEyOjI2OjE2IiwibmJmIjoxNjc1Njg2Mzc2LCJleHAiOjE2NzgyNzgzNzYsImlzcyI6Iml0dXJpbmciLCJhdWQiOiJpdHVyaW5nIiwicm9sZXMiOltdfQ.TLGvCrKh6nWkN6L3OYbsOVmLvPXB_-DL2cP_82FDozk",
        },
      });
      this.msgList = data.messages;
      console.log(data);
    },
  },
};
</script>

<style lang="scss" scoped>
.user-msg {
  position: relative;
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  z-index: 999;
  .van-nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1999;
    padding: 2px 0;
  }
  .body {
    padding: 50px 15px;
    .msg-item {
      padding: 15px 0;
      display: flex;
      justify-content: space-between;
      font-size: 14px;
      color: var(--book-name-font-black);
      border-bottom: 1px solid #eee;
      .item-left {
        width: 285px;
        .item-top {
          display: flex;
          justify-content: space-between;
          .top-left {
            .name {
              line-height: 20px;
            }
            .time {
              line-height: 23px;
              color: var(--more-font-grey);
            }
          }
          .top-right {
            p {
              color: var(--more-font-grey);
              background-color: #f8f8f8;
              line-height: 23px;
              padding: 0 4px 0 6px;
            }
          }
        }
        .main {
          background-color: #f8f8f8;
          line-height: 24px;
          padding: 15px;
          margin-top: 10px;
        }
      }
      .item-right {
        img {
          width: 40px;
          height: 40px;
          border-radius: 20px;
        }
      }
    }
  }
}
</style>